﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp001
{
    public partial class Editfrom : Form
    {
        public Editfrom()
        {
            InitializeComponent();
        }
        public Editfrom(int id,string author,int title,string createdtim)
        {
            this.id = id;
            txtUserName.Text = author;
            txtPassWord.Text = title.ToString();
            txtRetryPassWord.Text = createdtim.ToString();


        }
        private int id;
        /// <summary>
        /// 确认保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (id > 0)
            {
                
            }
            else
            {
                var autho = txtUserName.Text;
                var title = txtPassWord.Text;
                var createdtim = txtRetryPassWord.Text;

                if(!string.IsNullOrEmpty(autho))
                {
                    var sql = string.Format("insert into Articles (Title,Author,CreatedTim) values('{0}',{1},{2})",autho,title,createdtim);

                    var res = DbHelper.AddOrEditOrDeleteSave(sql);

                    if (res == 1)
                    {
                        MessageBox.Show("添加成工!", "提示");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("添加失败!", "提示");
                        this.Close();
                    }
                }
            }
            
        }
        /// <summary>
        /// 取消
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
